﻿// JScript source code


function hjsDisplayElement(id, display)
{
	var item = document.getElementById(id);
	if (item) {
		item.style.display = (display)?"block":"none";
	}
}


function hjsSetElementInnerHTML(id, val)
{
	var item = document.getElementById(id);

	if (item) {
		item.innerHTML = val;
	}
}


function ljh_show_section(section)
{
	var key;
	var sections = new Array("ljh-about", "ljh-products", "ljh-contact");
	
	for (key in sections) {
		hjsDisplayElement(sections[key], (sections[key] == section));
	}
}


function ljh_init_products_list()
{
	var key, html, products;
	
	products = ljh_get_products();
	
	html = "<li id=\"ljh-overview\"><a href=\"#\">"+
					ljh_lang_tran("Products list")+"</a></li>";
	
	for (key in products) {
		html += "<li><a href=\"#\" onclick=\"ljh_show_product(" +
		products[key].prod_id +	");\">"+
		products[key].title + "</a></li>\n";
	}
	
	hjsSetElementInnerHTML("ljh-primary-links",html);
}


function ljh_make_specification(prod)
{
	var html, key, item;

	if (!prod) {
		return "";
	}

	html = "<table class=\"ljh-data-table\">\r\n" +
		"<th colspan=\"2\">"+ljh_lang_tran("Specifications")+"</th>";

	for (key in prod.specifics) {	
		item = prod.specifics[key];
		html += "<tr><td>"+item.name+
			"</td><td>"+item.val+"</td></tr>\r\n";
	}
	
	html += "</table>\r\n";
	return html;
}


function ljh_show_product_image_html(prod)
{
	return "<img height=\"240\" width=\"320\" "+
		"src=\"/ljh_v10/images/ljh-product-" +
		prod.prod_id + ".jpg\" alt=\"" + prod.title + "\">";
}


function ljh_init_product(prod_id)
{
	var key, prod, products;
	
	products = ljh_get_products();
	
	for (key in products) {
		if (products[key].prod_id == prod_id) {
			prod = products[key];
			break;
		}
	}
	
	if (!prod) {
		return;
	}
	 	
	hjsSetElementInnerHTML("ljh-product-title",     prod.title);
	hjsSetElementInnerHTML("ljh-product-sub-title", prod.sub_title);
	hjsSetElementInnerHTML("ljh-product-content",   prod.directions);
	hjsSetElementInnerHTML("ljh-product-image",     
		ljh_show_product_image_html(prod));
	hjsSetElementInnerHTML("ljh-product-specification", 
		ljh_make_specification(prod));
}


function ljh_show_product(prod_id)
{
	ljh_show_section("none");
	ljh_init_product(prod_id);
	ljh_show_section("ljh-products");
}


function ljh_main()
{
	ljh_init_products_list();
	ljh_lang_replace_tags();
	ljh_init_product(1);
};
